package com.shanshan.crowd.controller;

import com.shanshan.crowd.entity.vo.AddressVO;
import com.shanshan.crowd.entity.vo.OrderProjectVO;
import com.shanshan.crowd.entity.vo.OrderVO;
import com.shanshan.crowd.service.api.OrderService;
import com.shanshan.crowd.util.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Description
 * @ClassName OrderProviderController
 * @Author 山山大魔王
 * @Date 2022/8/1 17:08
 * @Version 1.0
 */
@RestController
public class OrderProviderController {

    @Autowired
    OrderService orderService;

    @RequestMapping("/save/order/remote")
    ResultEntity<String> saveOrderRemote(@RequestBody OrderVO orderVO){
        try {

            orderService.saveOrder(orderVO);

            return ResultEntity.successWithoutData();

        } catch (Exception exception) {

            exception.printStackTrace();

            return ResultEntity.failed(exception.getMessage());

        }

    }


    @RequestMapping("/save/address/remote")
    ResultEntity<List<AddressVO>> saveAddressRemote(@RequestBody AddressVO addressVO){

        try {
            orderService.saveAddress(addressVO);

            return ResultEntity.successWithoutData();
        } catch (Exception exception) {
            exception.printStackTrace();
            return ResultEntity.failed(exception.getMessage());
        }

    }

    @RequestMapping("/get/address/vo/remote")
    ResultEntity<List<AddressVO>> getAddressVORemote(@RequestParam("memberId") Integer memberId){

        try {

            List<AddressVO> addressVOList = orderService.getAddressVOList(memberId);

            return ResultEntity.successWithData(addressVOList);
        } catch (Exception exception) {

            exception.printStackTrace();

            return ResultEntity.failed(exception.getMessage());
        }
    }

    @RequestMapping("/get/order/project/vo/remote")
    ResultEntity<OrderProjectVO> getOrderProjectVORemote(@RequestParam("returnId") Integer returnId){
        try {
            OrderProjectVO orderProjectVO = orderService.getOrderProjectVO(returnId);

            return ResultEntity.successWithData(orderProjectVO);
        } catch (Exception exception) {
            exception.printStackTrace();

            return ResultEntity.failed(exception.getMessage());
        }
    }
}
